//
//  ForgotPasswordViewController.m
//  TenThousand
//
//  Created by 我的 on 16/6/22.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "ForgotPasswordViewController.h"

@interface ForgotPasswordViewController ()
@property (weak, nonatomic) IBOutlet UIButton *agreeBtn;

@property (weak, nonatomic) IBOutlet UIButton *sureBtn;
@end

@implementation ForgotPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"找回登录密码";
    [self createLeft:[UIImage imageNamed:@"ZHSZicon_03"] leftClick:^{
        [self.navigationController popViewControllerAnimated:YES];
    } right:nil rightClick:nil];
    
     self.agreeBtn.selected = YES;//默认为选中
}
- (IBAction)agreeBtn:(UIButton *)sender {
    if (sender.selected) {
        sender.selected = NO;
        _sureBtn.enabled = NO;
    }else{
        sender.selected = YES;
        _sureBtn.enabled = YES;
    }
}

- (IBAction)sureBtn:(id)sender {
    
    if([_Password.text isEqualToString:@""]){
        [ToastView showInfoWithStatus:@"请输入新密码"];
    }else if([_erPassword.text isEqualToString:@""]){
        [ToastView showInfoWithStatus:@"请再次输入新密码"];
    }else if(![_erPassword.text isEqualToString:_Password.text]){
        [ToastView showInfoWithStatus:@"两次密码不一致, 请重新输入"];
    }else{
        
        [self changePassword];
        [[NSUserDefaults standardUserDefaults] setObject:_Password.text forKey:@"Password"];
        
//        NSString *passWord = [[NSUserDefaults standardUserDefaults] objectForKey:@"Password"];
        
    }

    
}


//修改密码接口
- (void)changePassword{
    
    
    
    //    http://test.open.wanyuanfu.net/api/user/openapi   User.GetUpdatePwd
    
    
    NSString *userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"LoginName"];
    NSDictionary *para = @{@"LoginName":userId,@"NewPassword":_Password.text};
    
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"EditPassword" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        
        [ToastView showInfoWithStatus:object[@"Message"]];
        
    } withFailureBlock:^(NSError *error) {
        NSLog(@"%@",error);
    } progress:nil];
    
}


//空白去键盘

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{
    
    [self.view.window endEditing:YES];
    
}


@end
